package com.huabo.audit.controller;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.hbfk.entity.DealUserToken;
import com.hbfk.entity.TblStaffUtil;
import com.hbfk.util.JsonBean;
import com.hbfk.util.ResponseFormat;
import com.hbfk.util.Tree;
import com.huabo.audit.oracle.entity.TblNbsjProject;
import com.huabo.audit.oracle.entity.TblNbsjProjectTeamEntity;
import com.huabo.audit.oracle.vo.TblNbsjTempleteVo;
import com.huabo.audit.oracle.vo.TblnbsjProjectRwfpVo;
import com.huabo.audit.oracle.vo.TblnbsjProjectVo;
import com.huabo.audit.oracle.vo.TblnbsjProjectZXYLVo;
import com.huabo.audit.service.TblAttachmentService;
import com.huabo.audit.service.TblNbsjAuditplanService;
import com.huabo.audit.service.TblNbsjOperateService;
import com.huabo.audit.service.TblNbsjPlanProjectService;
import com.huabo.audit.service.TblNbsjProjectService;
import com.huabo.audit.service.TblNbsjProjectteamService;
import com.huabo.audit.service.TblNbsjTempleteService;
import com.huabo.audit.service.TblNbsjTypeService;
import com.huabo.audit.service.TblOrganizaService;
import com.huabo.audit.service.TblStaffService;
import com.huabo.audit.util.R;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;

/**
 * 审计项目管理
 */
@RestController
@Slf4j
@Api(value = "审计项目管理", tags = { "审计项目管理接口" })
@RequestMapping(value = "/auditProject")
public class NbsjProjectController {
	
	@Resource
	public TblNbsjProjectService tblnbsjProjectService;
	
	@Resource
	public TblNbsjProjectteamService tblNbsjProjectteamService;
	
	@Resource
	private TblNbsjAuditplanService tblNbsjAuditplanService;
	
	@Resource
	private TblNbsjTypeService tblNbsjTypeService;
	
	@Resource
	private TblNbsjPlanProjectService tblNbsjPlanProjectService;
	
	@Resource
	private TblOrganizaService tblOrganizaService;
	
	@Resource
	public TblNbsjTempleteService tblNbsjTempleteService;
	
	@Resource
	public TblNbsjOperateService tblNbsjOperateService;
	
	@Resource
	private TblStaffService tblStaffService;
	
	@Resource
	private TblAttachmentService tblAttachmentService;
	
	/**
	 * 项目管理列表
	 */
	@GetMapping("/xmgl/project_list")
	@ApiOperation(value = "项目管理列表")
	public JsonBean project_list(HttpServletRequest request, TblnbsjProjectVo tblnbsjProjectVo,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "pageNumber", value = "分页当前页数", required = false) @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
			@ApiParam(name = "pageSize", value = "每页记录数", required = false) @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize) {

		JsonBean jsonBean = null;
		try {
			jsonBean = tblnbsjProjectService.projectPageList(token, pageNumber, pageSize,tblnbsjProjectVo);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	
	/**
	 * 项目管理-新增与修改
	 */
	@RequestMapping(value = "/xmgl/project_add", produces = "application/json; charset=utf-8",method = {RequestMethod.POST})
	@ApiOperation(value = "项目管理-新增与修改")
    public JsonBean project_add(HttpServletRequest request,@ApiParam(name="pj",value="实体",required=false)TblNbsjProject pj,
			 @ApiParam(name="token",value="登录用户token",required=false) @RequestHeader("token")String token,
			 @ApiParam(name="planStartDate",value="计划开始时间",required=false)String planStartDate,
			 @ApiParam(name="planEndDate",value="计划结束时间",required=false)String planEndDate,
			 @ApiParam(name="attids",value="附件id数组",required=false)String attids,
			 @ApiParam(name="pd_dx",value="",required=false)String pd_dx,
			 @ApiParam(name="pjTeamJson",value="项目小组json字符串",required=false)String pjTeamJson)throws Exception{
		JsonBean jsonBean = null;
		try {
			
//			pjTeamJson = "[{\"teamName\":\"小组1\",\"leaderid\":\"794458\",\"projectid\":\"797127\",\"teamId\":\"797128\"}]";
			
			jsonBean = this.tblnbsjProjectService.projectAdd(pj,token,planStartDate,planEndDate,attids,pd_dx,pjTeamJson);
			
		} catch (Exception e) {
			e.printStackTrace();
			ResponseFormat.retParam(1,1000,e.getMessage());
		}
		return jsonBean;
    }
	
	/**
	 * 项目管理-附件列表
	 */
    @GetMapping("/xmgl/project_file_list")
	@ApiOperation(value = "项目管理-附件列表")
	public JsonBean project_file_list(HttpServletRequest request, 
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "projectId", value = "业务主键", required = false) @RequestParam(value = "projectId", required = false) Integer projectId) {

		JsonBean jsonBean = null;
		try {
			jsonBean = this.tblAttachmentService.projectFileList(token,projectId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
    /**
     * 项目管理-附件删除
     */
    @GetMapping("/xmgl/project_file_del")
    @ApiOperation(value = "项目管理-附件删除")
    public R project_file_del(HttpServletRequest request, HttpServletResponse response,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="attId",value="附件主键ID",required=true) @RequestParam("attId") String attId) throws Exception {
    	return this.tblnbsjProjectService.removeAttInfoByAttId(token, attId);
    }
	
	/**
	 * 项目管理-删除
	 */
	@GetMapping("/xmgl/project_del")
	@ApiOperation(value = "项目管理-删除")
    public JsonBean project_del(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="projectid",value="主键",required=true)@RequestParam(value = "projectid", required = true) Integer projectid) {
        
        try {
			return tblnbsjProjectService.projectDelete(projectid, token);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return null;
    }
	/**
	 * 项目管理-明细
	 */
	@GetMapping("/xmgl/project_detail")
    @ApiOperation(value = "项目管理-明细")
    public JsonBean project_detail(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="projectid",value="主键",required=true)@RequestParam(value = "projectid", required = false) Integer projectid) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = tblnbsjProjectService.findProjectDetail(token,projectid);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
	
	/**
	 * 获取当前实施项目
	 */
	@GetMapping("/xmgl/curr_ss_project")
    @ApiOperation(value = "获取当前实施项目")
    public JsonBean curr_ss_project(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = tblnbsjProjectService.findProjectDetail(token,null);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
	
	/**
	 * 项目实施
	 */
	@GetMapping("/xmgl/xmproject_plan_cycurr")
    @ApiOperation(value = "项目实施")
    public JsonBean xmproject_plan_cycurr(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="projectid",value="主键",required=true)@RequestParam(value = "projectid", required = true) Integer projectid) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = tblnbsjProjectService.projectSS(token,projectid);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
	
	/**
	 * 项目小组列表
	 */
	@GetMapping("/xmgl/project_pjteam_list")
    @ApiOperation(value = "项目管理-项目小组列表")
    public JsonBean project_pjteam_list(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="projectid",value="主键",required=false)@RequestParam(value = "projectid", required = false) Integer projectid) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = tblNbsjProjectteamService.findProjectteamList(token,projectid);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
	
	@RequestMapping(value = "/getNbsjAuditPlanListForMerge", produces = "application/json; charset=utf-8", method = {RequestMethod.GET})
	@ApiOperation("项目管理-新增修改页面获取审计计划集合")
    public JsonBean getNbsjAuditPlanListForMerge(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = this.tblNbsjAuditplanService.getNbsjAuditPlanListForMergeNbsjProject(token);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
	
	@RequestMapping(value = "/getPlanProjectListByPlanId", produces = "application/json; charset=utf-8", method = {RequestMethod.GET})
	@ApiOperation(value = "项目管理-新增修改获取所选计划的计划项目")
	public JsonBean getPlanProjectListByPlanId(HttpServletRequest request,
			 @ApiParam(name="token",value="登录用户token",required=false) @RequestHeader("token")String token,
			 @ApiParam(name="planId",value="计划主键 ",required=true) @RequestParam(value = "planId", required = false) Integer planId)throws Exception{
		 JsonBean jsonBean = null;
			try {
//				jsonBean = this.tblNbsjPlanProjectService.getPlanProjectListByPlanIdPageInfo(token,project);
				jsonBean = this.tblNbsjPlanProjectService.findPlanProjectListInfoByPlanId(token,planId);
			} catch (Exception e) {
				ResponseFormat.retParam(1,1000,e.getMessage());
			}
			return jsonBean;
	}
	
	@RequestMapping(value = "/getNbsjAuditPlanDateInfo", produces = "application/json; charset=utf-8", method = {RequestMethod.GET})
	@ApiOperation("项目管理-新增修改页面获取审计计划后获取审计开始和结束时间")
    public JsonBean getNbsjAuditPlanDateInfo(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="planId",value="审计计划主键",required=true)@RequestParam(value = "planId", required = true)Integer planId) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = this.tblNbsjAuditplanService.getNbsjAuditPlanDateInfo(token,planId);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
	
	@RequestMapping(value = "/getNbsjTypeListForMerge", produces = "application/json; charset=utf-8", method = {RequestMethod.GET})
	@ApiOperation("项目管理-新增修改页面获取审计类型集合")
    public JsonBean getNbsjTypeListForMerge(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = this.tblNbsjTypeService.getNbsjTypeListForMerge(token);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
	
	@RequestMapping(value = "/getOrgTreeListByAuditObj", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "项目管理-新增修改获取审计对象的公司树形菜单")
	public JsonBean getOrgTreeListByAuditObj( HttpServletRequest request,
			@ApiParam(name="token",value="登录用户token",required=false) @RequestHeader("token")String token) throws Exception{
    	
    	JsonBean jsonBean = null;
		try {
			jsonBean = this.tblOrganizaService.getOrgTreeListByAuditObj(token,null);
		} catch (Exception e) {
			ResponseFormat.retParam(1,1000,e.getMessage());
		}
		return jsonBean;
	}
	
	
	@RequestMapping(value = "/getNbsjTempleteList", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
    @ApiOperation("审计模板/指引模板")
    public JsonBean getNbsjTempleteList(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
   		@ApiParam(name="pageNumber",value="分页当前页数",required=false)@RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
   		@ApiParam(name="pageSize",value="每页记录数",required=false)@RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
   		TblNbsjTempleteVo tblNbsjTempleteVo) {
    	JsonBean jsonBean = null;
    	try {
//    		tblNbsjTempleteVo.setTempType("0");
			jsonBean = tblNbsjTempleteService.selectNbsjTempleteListByPageInfo(token,pageNumber,pageSize,tblNbsjTempleteVo);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
	
	
	/**
	 * 项目任务分配
	 */
	@GetMapping("/xmgl/proj_role_list_xmgl")
	@ApiOperation(value = "项目任务分配列表")
	public JsonBean proj_role_list_xmgl(HttpServletRequest request, TblnbsjProjectRwfpVo tblnbsjProjectRwfpVo,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "pageNumber", value = "分页当前页数", required = false) @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
			@ApiParam(name = "pageSize", value = "每页记录数", required = false) @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize) {

		JsonBean jsonBean = null;
		try {
			jsonBean = tblnbsjProjectService.projectRwfpPageList(token, pageNumber, pageSize,tblnbsjProjectRwfpVo);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	/**
	 * 任务分配-列表
	 */
	@GetMapping("/xmgl/proj_rw_list")
	@ApiOperation(value = "任务分配-列表")
	public JsonBean proj_rw_list(HttpServletRequest request,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "pageNumber", value = "分页当前页数", required = false) @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
			@ApiParam(name = "pageSize", value = "每页记录数", required = false) @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
			@ApiParam(name = "projectid", value = "项目id", required = false) @RequestParam(value = "projectid", required = false) Integer projectid,
			@ApiParam(name = "targetId", value = "", required = false) @RequestParam(value = "targetId", required = false) Integer targetId) {

		JsonBean jsonBean = null;
		try {
			jsonBean = tblNbsjOperateService.projRwList(token, pageNumber, pageSize,projectid,targetId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	/**
	 * 查询项目下的所有小组成员
	 */
	@GetMapping("/xmgl/proj_pjteam_usr_list")
    @ApiOperation(value = "查询项目下的所有小组成员")
    public JsonBean proj_pjteam_usr_list(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="projectid",value="项目id",required=true)@RequestParam(value = "projectid", required = true) Integer projectid) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = tblNbsjProjectteamService.findProjectteamUsrList(token,projectid);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
	/**
	 * 分配-选择人员保存
	 */
	@RequestMapping(value = "/xmgl/jsfp_role_manage_save", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "分配-选择人员保存")
    public JsonBean jsfp_role_manage_save(HttpServletRequest request,
    		@ApiParam(name="ids",value="",required=false)String ids,
    		@ApiParam(name="teamStaffId",value="",required=false)Integer teamStaffId,
    		@ApiParam(name="projectId",value="",required=false)Integer projectId,
			@ApiParam(name="token",value="登录用户token",required=false) @RequestHeader("token")String token)throws Exception{
		JsonBean jsonBean = null;
		try {
			jsonBean = this.tblnbsjProjectService.jsfpRoleManageSave(token, ids, teamStaffId, projectId);
			
		} catch (Exception e) {
			ResponseFormat.retParam(1,1000,e.getMessage());
		}
		return jsonBean;
    }
	
	/**
	 * 通过小组id，查询小组信息
	 */
	@GetMapping("/xmgl/proj_pjteam_info")
    @ApiOperation(value = "通过小组id，查询小组信息")
    public JsonBean proj_pjteam_info(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="teamId",value="主键",required=true)@RequestParam(value = "teamId", required = true) Integer teamId) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = tblNbsjProjectteamService.getPjteamInfoById(token,teamId);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
	/**
	 * 小组信息--新增修改
	 */
	@RequestMapping(value = "/xmgl/proj_pjteam_add", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "小组信息--新增修改")
    public JsonBean proj_pjteam_add(HttpServletRequest request,
    		@ApiParam(name="team",value="实体",required=false)TblNbsjProjectTeamEntity team,
    		@ApiParam(name="zystaffids",value="组员ids（用,分隔）",required=false)String zystaffids,
    		@ApiParam(name="leaderid",value="组长id",required=false)Integer leaderid,
    		@ApiParam(name="projectid",value="项目id",required=false)Integer projectid,
			@ApiParam(name="token",value="登录用户token",required=false) @RequestHeader("token")String token)throws Exception{
		JsonBean jsonBean = null;
		try {
			jsonBean = this.tblNbsjProjectteamService.pjItemAdd(token,team,zystaffids,leaderid,projectid);
			
		} catch (Exception e) {
			
			//修改异常！则新增小组
			team.setTeamId(null);
			jsonBean = this.tblNbsjProjectteamService.pjItemAdd(token,team,zystaffids,leaderid,projectid);
			
			ResponseFormat.retParam(0,1000,e.getMessage());
		}
		return jsonBean;
    }
	
	/**
	 * 通过小组id，删除小组信息
	 */
	@GetMapping("/xmgl/proj_pjteam_del")
    @ApiOperation(value = "通过小组id，删除小组信息")
    public JsonBean proj_pjteam_del(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="teamId",value="主键",required=true)@RequestParam(value = "teamId", required = true) Integer teamId) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = tblNbsjProjectteamService.pjItemDelete(token,teamId);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
	
	/**
	 * 修改项目经理
	 */
	@RequestMapping(value = "/xmgl/proj_pm_modi", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "修改项目经理")
    public JsonBean proj_pm_modi(HttpServletRequest request,
    		@ApiParam(name="pmId",value="项目经理id",required=false)Integer pmId,
    		@ApiParam(name="projectid",value="项目id",required=false)Integer projectid,
			@ApiParam(name="token",value="登录用户token",required=false) @RequestHeader("token")String token)throws Exception{
		JsonBean jsonBean = null;
		try {
			jsonBean = this.tblnbsjProjectService.pjPmModi(token,pmId,projectid);
			
		} catch (Exception e) {
			ResponseFormat.retParam(1,1000,e.getMessage());
		}
		return jsonBean;
    }
	/**
	 * 启动
	 */
	@RequestMapping(value = "/xmgl/proj_pj_start", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "启动")
    public JsonBean proj_pj_start(HttpServletRequest request,
    		@ApiParam(name="projectid",value="项目id",required=false)Integer projectid,
			@ApiParam(name="token",value="登录用户token",required=false) @RequestHeader("token")String token)throws Exception{
		JsonBean jsonBean = null;
		try {
			jsonBean = this.tblnbsjProjectService.pjStart(token,projectid);
			
		} catch (Exception e) {
			ResponseFormat.retParam(1,1000,e.getMessage());
		}
		return jsonBean;
    }
	
	/**
	 * 项目执行一览
	 */
	@GetMapping("/sjgl/project_run_month")
	@ApiOperation(value = "项目执行一览列表")
	public JsonBean project_run_month(HttpServletRequest request, TblnbsjProjectZXYLVo tblnbsjProjectZXYLVo,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "pageNumber", value = "分页当前页数", required = false) @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
			@ApiParam(name = "pageSize", value = "每页记录数", required = false) @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize) {

		JsonBean jsonBean = null;
		try {
			jsonBean = tblnbsjProjectService.projectZxylPageList(token, pageNumber, pageSize,tblnbsjProjectZXYLVo);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	
	
	
	/**
	 * 选择人员-左侧部门
	 */
	@RequestMapping(value = "/htdl/findOrganizationByTreeAllss", method = {RequestMethod.POST},produces = "application/json; charset=utf-8")
	@ApiOperation(value = "选择人员-左侧部门")
	public @ResponseBody String htdlfindOrganizationByTree(@ApiParam(name="nodeId",value="nodeId",required=false)BigDecimal nodeId,
														   @ApiParam(name="type",value="type",required=false)String type,
														   @ApiParam(name="orgId",value="orgId",required=false)BigDecimal orgId,
														   @ApiParam(name="idname",value="idname",required=false)String idname,
														   @ApiParam(name="textname",value="textname",required=false)String textname,
														   @ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token") String token,
														   @ApiParam(name="staffId",value="登录用户主键",required=false)String staffId,
														   HttpServletRequest request) throws Exception {
		String json = "";
		if (null == nodeId) {
			nodeId = orgId;
			if (null == orgId) {
				TblStaffUtil user = DealUserToken.parseUserToken(token);
				nodeId = user.getCurrentOrg().getOrgid();
			}
		}
		if (StringUtils.isNotBlank(type)) {
			List<Tree> list = this.tblOrganizaService.getTrees(nodeId);
			for (Tree tree : list) {
				if (!tree.getIsParent()) {
					tree.setTarget("mainFramex");
					tree.setUrl("/nbkz/pjlx/list?pid=" + tree.getId() + "&idname=" + idname + "&textname=" + textname);
				}
			}
			json = JSONObject.toJSONString(list);
		} else {
			List<Tree> list = this.tblOrganizaService.getNodeAlls(nodeId);
			for (Tree tree : list) {
				setUrlByTree(tree, "/nbkz/pjlx/list?idname=" + idname + "&textname=" + textname + "&pid=");
			}
			json = JSONObject.toJSONString(list);
		}
		return json;
	}
	private void setUrlByTree(Tree tree, String url) {
		for (Tree tre : tree.getChildren()) {
			/// if (!tre.getIsParent()) {
			tre.setTarget("mainFramex");
			tre.setUrl(url + tre.getId());
			// }
			if (tre.getChildren().size() > 0) {
				setUrlByTree(tre, url);
			}
		}
	}
	/**
	 * 选择人员-人员列表
	 */
	@RequestMapping(value = "/htdl/list", method = {RequestMethod.POST},produces = "application/json; charset=utf-8")
	@ApiOperation(value = "选择人员-人员列表")
	public String htdluserListss(HttpServletRequest request,
									   @ApiParam(name="pid",value="pid",required=true)String pid,
									   @ApiParam(value = "pageNumber",required = false,defaultValue = "1")Integer pageNumber,
									   @ApiParam(value = "pageSize",required = false,defaultValue = "10")Integer pageSize,
									   @ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token") String token,
									   @ApiParam(name="staffId",value="登录用户主键",required=false)String staffId) {
		String result = null;
		try {
			Map<String,Object>  resultMap = this.tblStaffService.findAllPageBeanPid(pid,pageNumber,pageSize,token,staffId);
			JSONObject jsonObj = new JSONObject(resultMap);
			result = jsonObj.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
	/**
	 * 查询人员明细
	 */
	@GetMapping("/htdl/usr_detail")
    @ApiOperation(value = "查询人员明细")
    public JsonBean usr_detail(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="staffid",value="主键",required=true)@RequestParam(value = "staffid", required = true) Integer staffid) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = tblStaffService.findUsrDetail(token,staffid);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
	
	/**
	 * 查询审计模板下业务单元数量
	 */
	@GetMapping("/xmgl/tempele_biz_cnt")
    @ApiOperation(value = "查询审计模板下业务单元数量")
    public JsonBean tempele_biz_cnt(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="templeteId",value="",required=true)@RequestParam(value = "templeteId", required = true) Integer templeteId) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = tblnbsjProjectService.getTempeleBizCnt(token,templeteId);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
	
	
	/*
	*//**
     * 操作项目是否归档以及归档的业务
     
    @RequestMapping(value = "/xmgd/save", produces = "application/json; charset=utf-8")
    public
    @ResponseBody
    String save(String selectedData, Integer numPrice, String dateEndTime,HttpServletRequest request) throws ParseException {
        // 获取当前所属的项目
        TblNbsjProjectEntity selectProject = tblnbsjProjectService.getSelectProject();
        TblStaff user=(TblStaff) request.getSession().getAttribute("longUser");
        if (null != selectProject) {
        	//归档前，需要审批完成报告
        	List<TblReportEntity> reportList = tblReportService.findNoReportByProjectId(selectProject.getProjectId());
        	if(reportList!=null) {
        		return JsonBean.error("审计报告未审批完成，无法归档");
        	}
            // 根据项目查看当前项目是否归档
            List<TblNbsjArchiveEntity> arcList = tblNbsjProjectArchiveService.getTblNbsjArchiveList(selectProject);
            if (arcList.size() == 0) {
                try {
                    String[] selectedDatalist = selectedData.split(",");
                    for (String str : selectedDatalist) {
                        String[] strlist = str.split("&");
                        String id = strlist[0];
                        if (id != null && id != "") {
                            Integer level = Integer.parseInt(strlist[1]);
                            TblNbsjArchiveEntity objTblNbsjArchive = new TblNbsjArchiveEntity();
                            objTblNbsjArchive.setEndtime(DateUtils.parse(dateEndTime));
                            objTblNbsjArchive.setLevel(level);
                            objTblNbsjArchive.setMenucode(id);
                            objTblNbsjArchive.setObjTblnbsjProject(selectProject);
                            objTblNbsjArchive.setObjTblStaff(user);
                            objTblNbsjArchive.setPrice(numPrice);
                            objTblNbsjArchive.setAcrtime(new Date());
                            tblNbsjProjectArchiveService.save(objTblNbsjArchive);//归档信息
                            selectProject.setStatus(TblNbsjProjectEntity.GD_STATUS);
                            selectProject.setCurrentStatre(TblNbsjProjectEntity.NO_SELECT);
                            selectProject.setFinishTime(DateUtils.parse(dateEndTime));
                            selectProject.setFilCode(request.getParameter("filCode"));//档案编号
                            selectProject.setFilName(request.getParameter("filName" ));//档案名称
                            this.tblnbsjProjectService.update();
                            //删除当前实施的项目,确保所有用户左侧没有已归档的项目
                            this.tblNbsjStaffSelectService.deleteByprojectId(selectProject.getProjectId());
                        } else {
                            return JsonBean.error("项目归档失败");
                        }
                    }
                } catch (Exception e) {
//                    logger.info("项目归档有误，请验证！！");
                    e.printStackTrace();
                    return JsonBean.error();
                }
                return JsonBean.success();
            } else {
//                logger.info("项目名称为：" + selectProject.getProjectName() + "已经归档");
                return JsonBean.error("项目已经归档");
            }
        }
        return JsonBean.error("归档失败");
    }
    /**
     * 项目归档
     
    @RequestMapping(value = "/sjgl/audit_project_flow_list")
    public ModelAndView audit_project_flow_list(HttpServletRequest request, Find find) {
        ModelAndView mv = new ModelAndView();
        TblNbsjProjectEntity selectProject = this.tblnbsjProjectService.getSelectProject();
        // 项目归档
        List<ArchiveMenuList> list = tblNbsjProjectArchiveService.getArchiveMenuList();
        List<TblNbsjArchiveEntity> tblNbsjArchiveList = tblNbsjProjectArchiveService.getTblNbsjArchiveList(selectProject);
        mv.addObject("ArchiveMenuList", list);
        if(null!=tblNbsjArchiveList&&tblNbsjArchiveList.size()>0) {
        	mv.addObject("archiveMoney", tblNbsjArchiveList.get(0).getPrice());
        }
        mv.addObject("selectProject", selectProject);
        mv.setViewName("nbsj/sjzj/audit_project_flow_list");
        return mv;
    }
    
    /**
     * 以往项目资料
     
    @RequestMapping(value = "/sjzb/project_proposal_yw")
    public ModelAndView project_proposal_yw(Integer pageNumber ,String projectname,HttpServletRequest request) {
        ModelAndView mv = new ModelAndView();
        TblNbsjProjectEntity selectProject = this.tblnbsjProjectService.getSelectProject();
        if (null != selectProject) {
            pageBean = this.tblnbsjProjectService.getProjectData(selectProject.getProjectId(),projectname, pageNumber, pageBean.getPageSize());
            mv.setViewName("nbsj/sjgl/sjgd_project_hold_list_data");
            mv.addObject("pageBean", pageBean);
            mv.addObject("projectname", projectname);
        } else {
            setErrorJsp("001",request);
            mv.setViewName("nbsj/main41");
        }
      //查询框代码
        String choiceSearch = request.getParameter("choiceSearch");
        if(choiceSearch == null || "".equals(choiceSearch)) {
        	choiceSearch = "hide";
        }
        mv.addObject("choiceSearch",choiceSearch); 			

        return mv;
    }
    
    @RequestMapping(value = "/sjzj/audit_report_list")
    public ModelAndView audit_report_list(HttpServletRequest request, Find find) {
//        logger.info("内部审计--审计终结--审计报告--列表页查询");
        String pageNumber = request.getParameter("pageNumber");
        pageBean = tblNbsjReportService.findAll(find, pageNumber == null ? 1 : Integer.parseInt(pageNumber), pageBean.getPageSize());
        ModelAndView mv = new ModelAndView();
        mv.addObject("pageBean", pageBean);
        mv.addObject("find", find);
        mv.addObject("view", find.getView());
      //查询框代码
        String choiceSearch = request.getParameter("choiceSearch");
        if(choiceSearch == null || "".equals(choiceSearch)) {
        	choiceSearch = "hide";
        }
        mv.addObject("choiceSearch",choiceSearch); 	
        mv.setViewName("nbsj/sjzj/audit_report_list");
        return mv;
    }
    
    @RequestMapping(value = "/sjzj/audit_report_toAdd")
    public ModelAndView audit_report_toAdd(HttpServletRequest request, Integer reportid) {
//        logger.info("内部审计--审计终结--审计报告--跳往新建页");
        ModelAndView mv = new ModelAndView();
        TblNbsjReportEntity report = new TblNbsjReportEntity();
        if (reportid != null && StringUtils.isNotBlank(reportid.toString())) {
            report = tblNbsjReportService.getTblNbsjReport(reportid);
        }
      //查询框代码
        String choiceSearch = request.getParameter("choiceSearch");
        if(choiceSearch == null || "".equals(choiceSearch)) {
        	choiceSearch = "hide";
        }
        mv.addObject("choiceSearch",choiceSearch); 	
        mv.setViewName("nbsj/sjzj/audit_report_add");
        mv.addObject("report", report);
        return mv;
    }
    
    @RequestMapping(value = "/sjzj/audit_report_add")
    public ModelAndView audit_report_add(HttpServletRequest request, TblNbsjReportEntity nbsjReport) {
//        logger.info("内部审计--审计终结--审计报告--保存");
        String startDate = request.getParameter("startdate");
        if (StringUtils.isNotBlank(startDate)) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            try {
                nbsjReport.setCreateTime(sdf.parse(startDate));
            } catch (ParseException e) {
//                logger.info("内部审计--审计终结--审计报告--保存--转换时间错误");
            }
        }
        tblNbsjReportService.saveTblNbsjReport(nbsjReport);
        return audit_report_toAdd(request, nbsjReport.getReportid());
    }
    
    @RequestMapping(value = "/sjzj/audit_report_zf")
    public ModelAndView audit_report_zf(HttpServletRequest request, Integer  reportid) {
        TblNbsjReportEntity nbsjReport = tblNbsjReportService.getTblNbsjReport(reportid);
        nbsjReport.setStatus(new BigDecimal(nbsjReport.STATUS_1));
        tblNbsjReportService.updateTblNbsjReport(nbsjReport);
        return audit_report_list(request, new Find(null));
    }
    @RequestMapping(value = "/sjzj/index_audit_report_trackback")
    public ModelAndView index_audit_report_trackback() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("nbsj/sjzj/index_audit_report_trackback");
        return mv;
    }
    @RequestMapping(value = "/sjzj/T06_AUDIT_PROJECT_04_EDIT")
    public ModelAndView T06_AUDIT_PROJECT_04_EDIT() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("nbsj/sjzj/T06_AUDIT_PROJECT_04_EDIT");
        return mv;
    }
    @RequestMapping(value = "/sjzj/edit_word")
    public ModelAndView edit_word() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("nbsj/sjzj/edit_word");
        return mv;
    }
    
    /**
     * 项目指引
     
    @RequestMapping(value = "/sjzb/index_auditobjective")
    public ModelAndView index_auditobjective(HttpServletRequest request) {
        ModelAndView mv = new ModelAndView();
        TblNbsjProjectEntity selectProject = this.tblnbsjProjectService.getSelectProject();
        if (null != selectProject) {
            TblNbsjTempleteEntity tbltemplete = selectProject.getTemp();
            if(tbltemplete == null){setErrorJsp("002",request);}
            mv.addObject("tempId", tbltemplete.getTempleteId());
            mv.addObject("sjzb", true);
            mv.addObject("isuse", request.getParameter("isuse"));
            String status = request.getParameter("status");
            mv.setViewName("nbsj/sjyj/def_tmpl_index");
            mv.addObject("status", status);
        } else {
            setErrorJsp("001",request);
            mv.setViewName("nbsj/main41");
        }
        return mv;
    }
    @RequestMapping(value = "/sjzb/imp_proposal_add")
    public ModelAndView imp_proposal_add() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("nbsj/sjzb/index_check_list_my");
        return mv;
    }
    @RequestMapping(value = "/sjzb/location_window_proposal_template_radio")
    public ModelAndView location_window_proposal_template_radio() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("nbsj/sjzb/location_window_proposal_template_radio");
        return mv;
    }
    /**
     * 清单管理
     
    @RequestMapping(value = "/sjzb/index_check_list")
    public ModelAndView index_check_list(HttpServletRequest request) {
        ModelAndView mv = new ModelAndView();
        TblNbsjProjectEntity project = this.tblnbsjProjectService.getSelectProject();
        if (project != null) {
        	if(project.getTemp()==null){
        		setErrorJsp("003",request);
        		mv.setViewName("nbsj/main41");
        	}else{
        		mv.setViewName("nbsj/sjzb/index_check_list");
        		mv.addObject("tempId", project.getTemp().getTempleteId());
        		mv.addObject("projectId", project.getProjectId());
        	}
        } else {
            setErrorJsp("001",request);
            mv.setViewName("nbsj/main41");
        }
        return mv;
    }
    /**
     * 清单管理 --tree
     
    @RequestMapping(value = "/sjzb/menu_left_tree_check_list")
    public ModelAndView menu_left_tree_check_list(String projectId, String tempId) {
        ModelAndView mv = new ModelAndView();
        mv.addObject("projectId", projectId);
        mv.addObject("tempId", tempId);
        mv.setViewName("nbsj/sjzb/menu_left_tree_check_list");
        return mv;
    }
    /**
     * 清单管理 --列表
     
    @RequestMapping(value = "/sjzb/check_list_all")
    public ModelAndView check_list_all(String projectId, String tempId) {
        ModelAndView mv = new ModelAndView();
        mv.addObject("projectId", projectId);
        mv.addObject("tempId", tempId);
        mv.setViewName("nbsj/sjzb/check_list_all");
        return mv;
    }
    
    /**
     * 归档项目查看列表查询
     *
     * @return
     * @author haoyuge
     
    @RequestMapping(value = "/sjgl/project_hold_list")
    public ModelAndView project_hold_list(HttpServletRequest request) {
//        logger.info("归档项目查看开始.....");
        ModelAndView mv = new ModelAndView();
        // String orgid=request.getParameter("orgid");
        try {
            TblStaff user = (TblStaff) request.getSession().getAttribute("longUser");
            // String projectName=request.getParameter("projectName");
            String pageNumber = request.getParameter("pageNumber");
            String projectname = request.getParameter("projectname");
            if (pageNumber == null || pageNumber == "") {
                pageNumber = "1";
            }
            mv.addObject("projectname", projectname);
            pageBean = this.tblnbsjProjectService.findByProjectList(projectname, user, Integer.parseInt(pageNumber), pageBean.getPageSize());
        } catch (NumberFormatException e) {
//            logger.info("查看项目归档列表有误");
            e.printStackTrace();
        }
        mv.addObject("pageBean", pageBean);
        mv.setViewName("nbsj/sjgl/project_hold_list");
      //查询框代码
        String choiceSearch = request.getParameter("choiceSearch");
        if(choiceSearch == null || "".equals(choiceSearch)) {
        	choiceSearch = "hide";
        }
        mv.addObject("choiceSearch",choiceSearch); 
        return mv;
    }
    /**
     * 项目查看
     *
     * @return 2016年6月22日 下午2:51:03 SongXiangYing
     * <p>
     * Description:
     * </p>
     
    @RequestMapping(value = "/sjgl/project_index2")
    public ModelAndView project_index2(HttpServletRequest request) {
        ModelAndView mv = new ModelAndView();
        String projectid = request.getParameter("projectid");
        mv.setViewName("nbsj/wdcx/project_index2");
        mv.addObject("projectid", projectid);
        mv.addObject("fication", request.getParameter("fication"));
        //request.getSession().setAttribute("selectProjectId", projectid);
        //为页面查找区域显隐藏赋值
        String choiceSearch = request.getParameter("choiceSearch");
        		if(choiceSearch == null || "".equals(choiceSearch)) {
        			choiceSearch = "hide";
        }
        mv.addObject("choiceSearch", choiceSearch );
        return mv;
    }
    @RequestMapping(value = "/xmzl/getLiftMenu", produces = "application/json; charset=utf-8")
    public
    @ResponseBody
    String getLiftMenu(BigDecimal nodeId, String type, BigDecimal projectId, String t, HttpServletRequest request) {
        TblNbsjProjectEntity project = this.tblnbsjProjectService.getSelectProject();
        if (projectId != null) {
            project = tblnbsjProjectService.getById(projectId.toString());
        }
        if (StringUtils.isNotBlank(t)) {
            String url = "";
            if (t.equals("0")) {
                url = "/nbsj/sjss/check_list_my_all?projectId=" + project.getProjectId() + "&type=view";
            } else {
                url = "/nbsj/sjyj/def_cat_list_zy?projectId=" + project.getProjectId() + "&type=view";
            }
            List<Tree> liftMenu = this.tblTargetTypeService.getTree(nodeId, new BigDecimal(project.getTemp().getTempleteId()), url);
            return JSONObject.toJSONString(liftMenu);
        } else {
            Tree liftMenu = null;
            try {
            	String fication = request.getParameter("fication");
                liftMenu = this.tblNbsjProjectPreviewService.getLiftMenu(project,fication);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return JSONObject.toJSONString(liftMenu);
        }
    }
    @RequestMapping(value = "/sjgl/menu_left_tree2")
    public ModelAndView menu_left_tree2(HttpServletRequest request) {
        ModelAndView mv = new ModelAndView();
        String projectId = request.getParameter("projectId");
        mv.setViewName("nbsj/wdcx/menu_left_tree2");
        mv.addObject("projectId", projectId);
        mv.addObject("fication", request.getParameter("fication"));
        return mv;
    }
    @RequestMapping(value = "/xmzl/view")
    public String preview(HttpServletRequest request) {
    	String projectId=request.getParameter("projectId");
    	String url=request.getParameter("url");//此路径只能接收1个参数，参数增加时，增加接收参数，否则参数无法传递
    	String type=request.getParameter("type");
        if (url.indexOf("?") != -1) {
            return "redirect:" + url + "&projectId="+projectId+"&view=view"+"&type="+type;
        } else {
            return "redirect:" + url + "?view=view"+ "&ckpe=1&projectId="+projectId;
        }
    }
    
    
    /**
     * 项目列表
     
    @RequestMapping(value = "/xmgl/project_list")
    public ModelAndView project_list(HttpServletRequest request) {
        int pageNumber = 1;
        String pstartDate = request.getParameter("pstartDates");
        String pendDate = request.getParameter("pendDates");
        String number = request.getParameter("pageNumber");
        String pmid = request.getParameter("pmids");
        String projectName = request.getParameter("projectNames");
        String projectSource = request.getParameter("projectSources");
        String status = request.getParameter("statuss");
        TblOrganization organization = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");
        TblNbsjProjectEntity project = new TblNbsjProjectEntity();
        if (projectName != null && projectName.length() > 0) {
            project.setPProjectName(projectName);
        }
        if (projectSource != null && projectSource.length() > 0) {
            project.setProjectSource(projectSource);
        }
        if (status != null && status.length() > 0) {
            project.setStatus(Integer.parseInt(status));
        }
        TblStaff user = (TblStaff) request.getSession().getAttribute("longUser");
        project.setTblcreater(user);
        if (number != null && number.length() > 0) {
            pageNumber = Integer.parseInt(number);
        }
        String SJLBQX = PropertyFileReader.getItem("role.sjlbqx");
        try {
            SJLBQX = new String(SJLBQX.getBytes("iso-8859-1"),"utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        ModelAndView mv = new ModelAndView();
        if (pmid != null && pmid.length() > 0) {
            TblStaff staff =  null ;//tblStaffService.findById(pmid);
            mv.addObject("pm", staff);
        }
        
        if(tblRoleService.findIsByJs(SJLBQX,user)){
            pageBean = tblnbsjProjectService.findTblnbsjProject(project, organization.getOrgid(), pstartDate, pendDate, pmid, pageNumber, pageBean.getPageSize());
        }else{
            pageBean = tblnbsjProjectService.findTblnbsjProjectByStaff(project, organization.getOrgid(), pstartDate, pendDate, pmid, pageNumber, pageBean.getPageSize(),user);
        }
        //当前用户实施的项目
        TblNbsjStaffSelectEntity oldtblNbsjStaffSelect = this.tblNbsjStaffSelectService.getByStaffId(user.getStaffid());
        if(null!=oldtblNbsjStaffSelect) {
        	mv.addObject("currentProjectid", oldtblNbsjStaffSelect.getProjectId());
        }

        String identifier = "";
        try {
            identifier = activityPluginsService.getoNState(ProcessEnum.SJ_XMGL.name());
        } catch (Exception e) {
            e.printStackTrace();
        }
        mv.addObject("identifier",identifier);
        mv.addObject("pstartDate", pstartDate);
        mv.addObject("pendDate", pendDate);
        mv.addObject("pro", project);
      //查询框代码
        String choiceSearch = request.getParameter("choiceSearch");
        if(choiceSearch == null || "".equals(choiceSearch)) {
        	choiceSearch = "hide";
        }
        mv.addObject("choiceSearch",choiceSearch);
        mv.setViewName("nbsj/xmgl/project_list");
        mv.addObject("pageBean", pageBean);
        return mv;
    }
    /**
     * 验证项目列表-项目新增-编号是否存在
     *
     * @param request
     * @return
     
    @RequestMapping(value = "/xmgl/xmproject_plan_isProjectcode")
    public @ResponseBody String xmproject_plan_add_is(HttpServletRequest request,TblNbsjProjectEntity project) {
        String code = request.getParameter("projectCode");
        TblOrganization attribute = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");
        if(project.getProjectId()==null){
	        List<TblNbsjProjectEntity> list = tblnbsjProjectService.isByProjectCode(code,attribute.getOrgid().toString());
	        if (list != null && list.size() > 0) {
	            return  "-1";
	        }
        }
        try {
            String ysc = request.getParameter("yscxm");
            String id = request.getParameter("plan");
            if (StringUtils.isNotEmpty(ysc) && ysc.trim().equals("y")){
                TblNbsjAuditplanEntity plan = tblnbsjauditPlanService.getById(id);
                plan.setOpinionstatus(TblNbsjAuditplanEntity.YSCXM.doubleValue());
                tblnbsjauditPlanService.updatePlan(plan);
            }
            xmlbUpdate(request, project);
            return project.getProjectId().toString();
        } catch (Exception e) {
            e.printStackTrace();
            return "0";
        }
       // return "redirect:xmproject_plan_modife?selectid=" + project.getProjectid();
       
    }
    /**
     * 查询该审计模板下是否有业务单元
     *
     * @param request
     * @return
     
    @RequestMapping(value = "/xmgl/findSonCountSjmb")
    public  @ResponseBody Integer findSonCountSjmb(HttpServletRequest request,
    		@RequestParam(value="tempid",required = true)String tempId) {
        Integer count = tblnbsjProjectService.findSonCountSjmb(tempId);
        return count;
    }
    
    
    /**
     * @Title: solution_codeIsExist 
    * @Description: “整改方案”,判断编号是否重复
    * @param request
    * @param solutioncode	整改方案编号
    * @return String
    * @throws
     
    @RequestMapping(value = "/zgfa/solution_codeIsExist",produces = "application/json;charset=utf-8")
    public @ResponseBody String solution_codeIsExist(HttpServletRequest request,String solutioncode) {
    	String orgid = request.getParameter("orgid");
    	List<TblNbsjReformSolutionEntity> list = tblNbsjReformSolutionService.solutionIsExist(solutioncode,orgid);
	     if (list != null && list.size() > 0) {
	         return list.size() + "";
	     }
	     return "0";
    	
    }
    	
    
    /**
     * 项目列表-新建项目
     *
     * @return
     
    @RequestMapping(value = "/xmgl/xmproject_plan_add")
    public ModelAndView xmproject_plan_add(HttpServletRequest request) {
//        logger.info("新建项目");
        ModelAndView mv = new ModelAndView();
        TblOrganization organization = (TblOrganization) request.getSession().getAttribute("hbOrgName");
		// 审计类型
		TblOrganization attribute = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");// 选择的机构
		List<TblNbsjTypeEntity> list = tblNbsjTypeService.findAll(attribute.getOrgid().toString());
		mv.addObject("sjlxList", list);
        List<TblNbsjAuditplanEntity> plans = tblnbsjauditPlanService.findByOpinionstatus(organization.getOrgid());
        mv.addObject("plans", plans);
      //查询框代码
        String choiceSearch = request.getParameter("choiceSearch");
        if(choiceSearch == null || "".equals(choiceSearch)) {
        	choiceSearch = "hide";
        }
        mv.addObject("choiceSearch",choiceSearch);
        mv.addObject("organization",organization);
        mv.setViewName("nbsj/xmgl/xmproject_plan_add");
        return mv;
    }
    /**
     * 项目列表-修改项目
     *
     * @return
     
    @RequestMapping(value = "/xmgl/xmproject_plan_modife")
    public ModelAndView xmproject_plan_modife(HttpServletRequest request) {
//        logger.info("修改项目");
        String id = request.getParameter("selectid");
        TblNbsjProjectEntity tblnbsjProject = tblnbsjProjectService.getById(id);
        Set<TblNbsjProjectTeamEntity> teams = tblnbsjProject.getTblProjectTeams();
        for (TblNbsjProjectTeamEntity tblnbsjProjectTeam : teams) {
            List<TblNbsjTeamstaffEntity> teamStaffs = tblnbsjProjectTeam.getTeamStaffs();
            for (TblNbsjTeamstaffEntity tblNbsjTeamStaff : teamStaffs) {
                if (tblNbsjTeamStaff.getStafftype().equals(TblNbsjTeamstaffEntity.LEADER)) {
                    tblnbsjProjectTeam.setLeaderName(tblNbsjTeamStaff.getStaff().getRealname());
                }
            }
        }
		// 审计类型
		TblOrganization attribute = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");// 选择的机构
		List<TblNbsjTypeEntity> list = tblNbsjTypeService.findAll(attribute.getOrgid().toString());
        ModelAndView mv = new ModelAndView();
        TblOrganization organization = (TblOrganization) request.getSession().getAttribute("hbOrgName");
        List<TblNbsjAuditplanEntity> plans = tblnbsjauditPlanService.findByOpinionstatus(organization.getOrgid());
        mv.addObject("plans", plans);
        mv.addObject("pro", tblnbsjProject);
        mv.addObject("teams", teams);
        mv.addObject("teamsize", teams.size());
        mv.addObject("sjlxList", list);
        mv.addObject("cyId",request.getParameter("cyId"));
        mv.addObject("tId",request.getParameter("tId"));
        mv.addObject("v",request.getParameter("v"));
        mv.setViewName("nbsj/xmgl/xmproject_plan_add");
      //查询框代码
        String choiceSearch = request.getParameter("choiceSearch");
        if(choiceSearch == null || "".equals(choiceSearch)) {
        	choiceSearch = "hide";
        }
        mv.addObject("choiceSearch",choiceSearch); 
        return mv;
    }
    @RequestMapping(value = "/xmgl/validate_group",produces = "application/json;charset=utf-8")
    public @ResponseBody String validate_group(HttpServletRequest request,String id) {
        TblNbsjProjectEntity tblnbsjProject = tblnbsjProjectService.getById(id);
        Set<TblNbsjProjectTeamEntity> teams = tblnbsjProject.getTblProjectTeams();
        for (TblNbsjProjectTeamEntity tblnbsjProjectTeam : teams) {
            List<TblNbsjTeamstaffEntity> teamStaffs = tblnbsjProjectTeam.getTeamStaffs();
            for (TblNbsjTeamstaffEntity tblNbsjTeamStaff : teamStaffs) {
                return JsonBean.success();
            }
        }
        return JsonBean.error("小组及成员未添加");
    }
    /**
     * 项目列表-详情
     *
     * @param request
     * @return
     
    @RequestMapping(value = "/xmgl/project_plan_disp")
    public ModelAndView project_plan_disp(HttpServletRequest request) {
        String projectid = request.getParameter("projectid");
//        logger.info("项目详情");
        ModelAndView mv = new ModelAndView();
        if (projectid != null && projectid.length() > 0) {
            TblNbsjProjectEntity tblnbsjProject = tblnbsjProjectService.getById(projectid);
            Set<TblNbsjProjectTeamEntity> teams = tblnbsjProject.getTblProjectTeams();
            for (TblNbsjProjectTeamEntity tblnbsjProjectTeam : teams) {
                List<TblNbsjTeamstaffEntity> teamStaffs = tblnbsjProjectTeam.getTeamStaffs();
                for (TblNbsjTeamstaffEntity tblNbsjTeamStaff : teamStaffs) {
                    if (tblNbsjTeamStaff.getStafftype().equals(TblNbsjTeamstaffEntity.LEADER)) {
                        tblnbsjProjectTeam.setLeaderName(tblNbsjTeamStaff.getStaff().getRealname());
                    }
                }
            }
            mv.addObject("teams", teams);

            mv.addObject("pro", tblnbsjProject);
        }
        mv.setViewName("nbsj/xmgl/project_plan_disp");
        return mv;
    }
    /**
     * 项目列表-添加附件
     *
     * @param file
     * @param request
     * @param projectid
     * @param session
     * @return
     
    @RequestMapping(value = "/xmgl/nbsj_plan_upload")
    public String fxsjcl_upload(MultipartFile file, HttpServletRequest request, String projectid, HttpSession session) {
//        logger.info("新建---添加附件");
        AttachmentService service = (AttachmentService) SpringContextHolder.getBean("AttachmentService");
        TblStaff user = (TblStaff) session.getAttribute("longUser");
        String fileName = file.getOriginalFilename();
        long timeInMillis = Calendar.getInstance().getTimeInMillis();
        String oldname = fileName.substring(0,fileName.lastIndexOf("."));
        String newname=fileName.replace(oldname, timeInMillis+"sjxm");
        boolean flag;
		try {
			flag = FtpUtil.uploadFile(newname, file.getInputStream());
			if(flag){
//	    		 logger.info("上传成功");
	    	}else{
//	    		 logger.info("上传失败");
	    	}
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		long size = file.getSize();
        TblAttachmentEntity a = new TblAttachmentEntity();
        a.setAttname(fileName);
        TblNbsjProjectEntity project = new TblNbsjProjectEntity();
        project.setProjectId(Integer.valueOf(projectid));
        a.getTblAttprojects().add(project);
        a.setAttpath(newname);
        a.setAttsize(new BigDecimal(size / 1024));
        a.setUploader(user.getUsername());
        a.setUploadtime(new Date());
        service.add(a);
        String cyId = request.getParameter("cyId");
        String tId = request.getParameter("tId");
        String v = request.getParameter("v");
      //查询框代码
        String choiceSearch = request.getParameter("choiceSearch");
        if(choiceSearch == null || "".equals(choiceSearch)) {
        	choiceSearch = "hide";
        }
        return "redirect:xmproject_plan_modife?selectid=" + projectid+"&cyId="+cyId+"&tId="+tId+"&v="+v+"&choiceSearch="+choiceSearch;
    }
    /**
     * 项目列表-删除附件
     *
     * @param request
     * @param projectid
     * @param attid
     * @return
     
    @RequestMapping(value = "/xmgl/delete_nbsj_plan_upload")
    public String fxsjcl_upload(HttpServletRequest request, String projectid, String attid) {
        if (StringUtils.isNotBlank(attid)) {
            AttachmentService service = (AttachmentService) SpringContextHolder.getBean("AttachmentService");
            service.delete(attid);
        }
        return "redirect:xmproject_plan_modife?selectid=" + projectid;
    }
    /**
     * 保存项目
     *
     * @return
     
    @RequestMapping(value = "/xmgl/project_proposal_edit")
    public String xmgl_projectSave(HttpServletRequest request, TblNbsjProjectEntity project) {
        try {
            String ysc = request.getParameter("yscxm");
            String id = request.getParameter("plan");
            if (StringUtils.isNotEmpty(ysc) && ysc.trim().equals("y")){
                TblNbsjAuditplanEntity plan = tblnbsjauditPlanService.getById(id);
                plan.setOpinionstatus(TblNbsjAuditplanEntity.YSCXM.doubleValue());
                tblnbsjauditPlanService.updatePlan(plan);
            }
            xmlbUpdate(request, project);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "redirect:xmproject_plan_modife?selectid=" + project.getProjectId();
    }
    /**
      * @Author: TYB
      * @Date: 2016-12-22 上午 9:54
      * @Des: 项目管理 修改审批
      
    @RequestMapping(value = "/xmgl_update_sp", produces = "application/json; charset=utf-8")
    public @ResponseBody String xmgl_update_sp(HttpServletRequest request,TblNbsjProjectEntity project){
        String cyId = request.getParameter("cyId");
        try {
            TblNbsjProjectEntity pro = xmlbUpdate(request, project);
            pro.setExamineType(TblNbsjProjectEntity.EXAMINETYPE2);
            tblnbsjProjectService.saveOrUpdate(pro);
            TblCirculation c = tblCirculationService.get(cyId);
            c.setCyname(pro.getPProjectName());
            c.setCystate(TblCirculation.STATE_FQ);
            tblCirculationService.update(c);
        } catch (Exception e) {
            JsonBean.error("修改审批失败");
            e.printStackTrace();
        }
        return JsonBean.success();
    }
    private TblNbsjProjectEntity xmlbUpdate(HttpServletRequest request, TblNbsjProjectEntity project) {
        String pmid = request.getParameter("pmid");
        String enddate = request.getParameter("pendDate");
        String startdate = request.getParameter("pstartDate");
        String tempzyid = request.getParameter("tempzyid");//指引模板
        TblOrganization organization1 = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");
        if (project.getProjectId() != null) {
			// 修改开始
            TblNbsjProjectEntity tblnbsjProject = tblnbsjProjectService.getById(project.getProjectId().toString());
            tblnbsjProject.setAuditType(project.getAuditType());
            tblnbsjProject.setPlanYear(project.getPlanYear());
            tblnbsjProject.setCosts(project.getCosts());
            tblnbsjProject.setPProjectName(project.getPProjectName());
            tblnbsjProject.setProjectSource(project.getProjectSource());
            tblnbsjProject.setPurpose(project.getPurpose());
            tblnbsjProject.setScopes(project.getScopes());
            tblnbsjProject.setPursuant(project.getPursuant());
            tblnbsjProject.setComments(project.getComments());
            tblnbsjProject.setProDesc(project.getProDesc());
            tblnbsjProject.setProSjfs(project.getProSjfs());
            if(StringUtils.isNotEmpty(tempzyid)){
                TblNbsjTempleteEntity templetezy = tblNbsjTempleteService.getById(new BigDecimal(tempzyid));//指引模板
                tblnbsjProject.setTemp(templetezy);
            }
            tblnbsjProject.setCreateTime(new Date());
            tblnbsjProject.setUpdateStatus(TblNbsjProjectEntity.UPDATEYES);
            if(tblnbsjProject.getExamineType()!=null){tblnbsjProject.setExamineType(project.getExamineType());}

            //examinetype
            TblStaff pm = new TblStaff();
            pm.setStaffid(new BigDecimal(pmid));
            /*主审人
            String umpireid = request.getParameter("umpireid");
            TblStaff um = new TblStaff();
            um.setStaffid(new BigDecimal(umpireid));
            /*质控经理
            String controlid = request.getParameter("controlid");
            TblStaff con = new TblStaff();
            con.setStaffid(new BigDecimal(controlid));
            tblnbsjProject.setTblPm(pm);
            //tblnbsjProject.setTblcontrol(con);
            //tblnbsjProject.setTblumpe(um);
            String tempid = request.getParameter("tempid");//审计模板
			String protempid = request.getParameter("protempid");
			//修改审计模板
			if (StringUtils.isNotEmpty(tempid)) { 
				// 如果审计模板再次修改
				if(!tempid.equals(protempid)){
					TblNbsjTempleteEntity templete = tblNbsjTempleteService.getById(new BigDecimal(tempid));
					TblNbsjTempleteEntity temp = new TblNbsjTempleteEntity();
					temp.setTempType(TblNbsjTempleteEntity.COPY_TYPE);
					temp.setCreateDate(templete.getCreateDate());
					temp.setTempleteCode(templete.getTempleteCode());
					temp.setTempleteDesc(templete.getTempleteDesc());
					Set<TblOrganization> orgs = templete.getOrganizations();
					if (orgs != null && orgs.size() > 0) {
						for (TblOrganization org : orgs) {
							temp.getOrganizations().add(org);
						}
					}
					temp.setStaffId(templete.getStaffId());
					temp.setTempleteType(templete.getTempleteType());
					temp.setUpdateStaffId(templete.getUpdateStaffId());
					temp.setUpdateDate(templete.getUpdateDate());
					temp.setStatus(templete.getStatus());
					temp.setTempleteName(templete.getTempleteName());
					tblNbsjTempleteService.save(temp);
					tblnbsjProject.setTemp(temp);
					tblnbsjProject.setTblorg(organization1);
					// if(!tempid.equals(tblnbsjProject.getTbltemplete().getTempleteId().toString())){
					List<TblTargetTypeEntity> list = tblTargetTypeService.findByAllMB(tempid);
					if (list != null && list.size() > 0) {
						for (TblTargetTypeEntity tblTargetType : list) {
							TblTargetTypeEntity target = new TblTargetTypeEntity();
							target.setCreateTime(tblTargetType.getCreateTime());
							target.setNbsjTemplete(temp);
							target.setParentId(tblTargetType.getParentId());
							target.setStatus(TblTargetTypeEntity.TEMP_NUMBER);//TEMP_NUMBER 0 ;ZY_NUMBER 1
							target.setTargetDesc(tblTargetType.getTargetDesc());
							target.setTargetName(tblTargetType.getTargetName());
							tblTargetTypeService.save(target);
							List<TblAduitProGramEntity> grams = tblAduitProGramService.findByALL(tblTargetType.getTargetId().toString());
							if (grams != null && grams.size() > 0) {
								for (TblAduitProGramEntity gram : grams) {
									TblAduitProGramEntity prog = new TblAduitProGramEntity();
									prog.setBioData(gram.getBioData());
									prog.setTarget(target);
									prog.setControl(gram.getControl());
									prog.setBusinessType(gram.getBusinessType());
									prog.setStatus(TblAduitProGramEntity.TEMP_NUMBER);
									prog.setCreateTime(gram.getCreateTime());
									prog.setNbsjTemplete(temp);
									prog.setRiskPoint(gram.getRiskPoint());
									prog.setRiskSource(gram.getRiskSource());
									prog.setSuditProcess(gram.getSuditProcess());
									prog.setUpdateTime(gram.getUpdateTime());
									tblAduitProGramService.save(prog);
								}
							}
							capyMb(tblTargetType.getTargetId().toString(), temp, target.getTargetId().toString());
						}
					}
					//删除之前分配的任务
					//删除任务
					
						 List<TblNbsjAuthorizationEntity> nbsjauthorizatoin = this.tblNbsjAuthorizationService.getByProjectId(project.getProjectId());
						 if(null!=nbsjauthorizatoin&&nbsjauthorizatoin.size()>0) {
							 for (TblNbsjAuthorizationEntity tblNbsjAuthorization : nbsjauthorizatoin) {
								 if(null!=nbsjauthorizatoin) {
									 TblNbsjOperateEntity oper = tblNbsjOperateService.findByAuthId(tblNbsjAuthorization.getAuthId());
									 tblNbsjOperateService.delete(oper);
									 this.tblNbsjAuthorizationService.delete(tblNbsjAuthorization);
								 }
							 }
						 }
					//一是已经是在项目里的，已经复制出来的，可以删除
					//二是没在项目里的，没复制出来的，不能删除
					if(StringUtils.isNotEmpty(protempid)) {
						tblAduitProGramService.deleteZy(protempid);
						tblTargetTypeService.deleteByZY(protempid);
						tblNbsjTempleteService.delete(new BigDecimal(protempid));
					}
				}
			}
            try {
                if (startdate != null && startdate.length() > 0) {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    tblnbsjProject.setStartDate(sdf.parse(startdate));
                }
                if (enddate != null && enddate.length() > 0) {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    tblnbsjProject.setEndDate(sdf.parse(enddate));
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
            //项目对象
            String pd_dx = request.getParameter("pd_dx");
            String org = request.getParameter("belongsto");
            if (StringUtils.isNotEmpty(pd_dx) && pd_dx.equals("yh")){
                TblStaff staff = tblStaffNewService.get(Integer.valueOf(org));
                tblnbsjProject.setTblnbsjstaffs(staff);
                TblOrganization o = organizationService.findById(staff.getTblOrganization().getOrgid().toString());
                tblnbsjProject.setTblnbsjorgs(null);
                //tblnbsjProject.setTblnbsjorgs(o);
            }else {
                TblOrganization organization = organizationService.findById(org);
                tblnbsjProject.setTblnbsjorgs(organization);
                tblnbsjProject.setTblnbsjstaffs(null);
            }
            //被审计单位
			//String belongsto = request.getParameter("belongsto");
			//String belongstoText = request.getParameter("belongstoText");
			//project.setOrgids(belongsto);
			//project.setOrgidNames(belongstoText);
			
            String plan = request.getParameter("plan");
            TblNbsjAuditplanEntity jplan = tblnbsjauditPlanService.getById(plan);
            tblnbsjProject.setTblnbsjPlan(jplan);
            //保存附件
            String attids = request.getParameter("attids");
            if (StringUtils.isNotBlank(attids)){
            	String[] ids = attids.split(",");
            	for (int i = 0; i < ids.length; i++) {
            		TblAttachmentEntity att = attachmentService.findById(ids[i].trim());
            		tblnbsjProject.getTblprojectAtts().add(att);
            	}
            }            
            tblnbsjProjectService.saveOrUpdate(tblnbsjProject);
            this.project_team_save(request, project.getProjectId().toString());
            return tblnbsjProject;
        }else {
        	//新建项目
            try {
                if (startdate != null && startdate.length() > 0) {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    project.setStartDate(sdf.parse(startdate));
                }
                if (enddate != null && enddate.length() > 0) {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    project.setEndDate(sdf.parse(enddate));
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
            String plan = request.getParameter("plan");
            TblNbsjAuditplanEntity jplan = tblnbsjauditPlanService.getById(plan);
            project.setTblnbsjPlan(jplan);
            TblStaff pm = new TblStaff();
            pm.setStaffid(new BigDecimal(pmid));
            project.setTblPm(pm);
            project.setTblorg(organization1);
            String tempid = request.getParameter("tempid");
//            if (tempid != null) {
			//第一次新增审计模板
			if (StringUtils.isNotEmpty(tempid)) {
				//选择的方案模板(来自方案模板)
				TblNbsjTempleteEntity templete = tblNbsjTempleteService.getById(new BigDecimal(tempid));
				//复制审计模板
				TblNbsjTempleteEntity temp = new TblNbsjTempleteEntity();
				temp.setTempType(TblNbsjTempleteEntity.COPY_TYPE);
				temp.setCreateDate(templete.getCreateDate());
				temp.setTempleteCode(templete.getTempleteCode());
				temp.setTempleteDesc(templete.getTempleteDesc());
				Set<TblOrganization> orgs = templete.getOrganizations();
				if (orgs != null && orgs.size() > 0) {
					for (TblOrganization org : orgs) {
						temp.getOrganizations().add(org);
					}
				}
				temp.setStaffId(templete.getStaffId());
				temp.setTempleteType(templete.getTempleteType());
				temp.setUpdateStaffId(templete.getUpdateStaffId());
				temp.setUpdateDate(templete.getUpdateDate());
				temp.setStatus(templete.getStatus());
				temp.setTempleteName(templete.getTempleteName());
				tblNbsjTempleteService.save(temp);
				project.setTemp(temp);
				if (StringUtils.isNotEmpty(tempzyid)) {
					TblNbsjTempleteEntity templetezy = tblNbsjTempleteService.getById(new BigDecimal(tempzyid));
					project.setTemp(templetezy);
				}

				List<TblTargetTypeEntity> list = tblTargetTypeService.findByAllMB(tempid);
				if (list != null && list.size() > 0) {
					for (TblTargetTypeEntity tblTargetType : list) {
						TblTargetTypeEntity target = new TblTargetTypeEntity();
						target.setCreateTime(tblTargetType.getCreateTime());
						target.setNbsjTemplete(temp);
						target.setParentId(tblTargetType.getParentId());
						target.setStatus(TblTargetTypeEntity.TEMP_NUMBER);
						target.setTargetDesc(tblTargetType.getTargetDesc());
						target.setTargetName(tblTargetType.getTargetName());
						tblTargetTypeService.save(target);
						List<TblAduitProGramEntity> grams = tblAduitProGramService.findByALL(tblTargetType.getTargetId().toString());
						if (grams != null && grams.size() > 0) {
							for (TblAduitProGramEntity gram : grams) {
								TblAduitProGramEntity prog = new TblAduitProGramEntity();
								prog.setBioData(gram.getBioData());
								prog.setTarget(target);
								prog.setControl(gram.getControl());
								prog.setBusinessType(gram.getBusinessType());
								prog.setStatus(TblAduitProGramEntity.TEMP_NUMBER);
								prog.setCreateTime(gram.getCreateTime());
								prog.setNbsjTemplete(temp);
								prog.setRiskPoint(gram.getRiskPoint());
								prog.setRiskSource(gram.getRiskSource());
								prog.setSuditProcess(gram.getSuditProcess());
								prog.setUpdateTime(gram.getUpdateTime());
								tblAduitProGramService.save(prog);
							}
						}
						capyMb(tblTargetType.getTargetId().toString(), temp, target.getTargetId().toString());
					}
				}
			}
            //项目对象
            String pd_dx = request.getParameter("pd_dx");
            String org = request.getParameter("belongsto");
            if (StringUtils.isNotEmpty(pd_dx) && pd_dx.equals("yh")){
                TblStaff staff = tblStaffNewService.get(Integer.valueOf(org));
                project.setTblnbsjstaffs(staff);
                TblOrganization o = organizationService.findById(staff.getTblOrganization().getOrgid().toString());
                project.setTblnbsjorgs(null);
            }else {
                TblOrganization organization = organizationService.findById(org);
                project.setTblnbsjorgs(organization);
                project.setTblnbsjstaffs(null);
            }
			
            //被审计单位
            project.setStatus(0);
            project.setFpStatus(0);//项目任务分配状态
            project.setAssigbedControlTime(new Date());
            project.setAssigbedumpeTime(new Date());
            project.setAssigbedpmTime(new Date());
            project.setCreateTime(new Date());
            project.setUpdateStatus(TblNbsjProjectEntity.UPDATEYES);
            TblStaff user = (TblStaff) request.getSession().getAttribute("longUser");
            project.setTblcreater(user);
            project.setCurrentStatre(TblNbsjProjectEntity.NO_SELECT);
            //保存附件
            String attids = request.getParameter("attids");
            if (StringUtils.isNotBlank(attids)){
            	String[] ids = attids.split(",");
            	for (int i = 0; i < ids.length; i++) {
            		TblAttachmentEntity att = attachmentService.findById(ids[i].trim());
            		project.getTblprojectAtts().add(att);
            	}
            }
            tblnbsjProjectService.save(project);
            //审计小组
            this.project_team_save(request, project.getProjectId().toString());
            return project;
        }
    }
    /**
     * 项目列表-保存小组
     *
     * @return
     
    public void project_team_save(HttpServletRequest request,String pid) {
        TblStaff creator = (TblStaff) request.getSession().getAttribute("longUser");
        	String[] teamids = request.getParameterValues("teamids");
        	if(null!=teamids&&teamids.length>0) {
				for (int i = 0; i < teamids.length; i++) {
					TblNbsjProjectTeamEntity projectTeam = tblnbsjProjectTeamService.getById(teamids[i]);
					tblnbsjProjectTeamService.deleteProjectTeamInfo(Integer.valueOf(pid),projectTeam.getTeamId());
				}
        	}
        	String[] teamNames = request.getParameterValues("teamNames");
        	
            String[] staffids = request.getParameterValues("staffids");
				
        	String[] userids = request.getParameterValues("userids");
            TblNbsjProjectTeamEntity team = null;
            
            if(staffids!=null) {
            for (int i = 0; i < staffids.length; i++) {
//	                logger.info("新建项目--小组成员");
	                team = new TblNbsjProjectTeamEntity();
	                team.setCreateUserId(creator.getStaffid().intValue());
	                team.setCreateTime(new Date());
	                team.setTeamName(teamNames[i]);
	            if (pid != null && pid.length() > 0) {
	                TblNbsjProjectEntity project = tblnbsjProjectService.getById(pid);
	                team.getTblTeamProjects().add(project);
	            }
	            if (staffids[i]!= null && staffids[i].length() > 0) {
	                TblStaff staff = null;// tblStaffService.findById(staffids[i]);
	                if (userids[i] != null && userids[i].length() > 0) {
	                    String[] strs = userids[i].split(",");
	                    List<TblStaff> crewList = new ArrayList<TblStaff>();
	                    for (String string : strs) {
	                        if (StringUtils.isNotBlank(string)) {
	                            TblStaff crew = null;// tblStaffService.findById(string.trim());
	                            crewList.add(crew);
	                        }
	                    }
	                    tblnbsjProjectTeamService.saveTblNbsjProjectteam(team);
	                }
	            }
        	  }
            }
    }
	public void capyMb(String parentid, TblNbsjTempleteEntity temp, String newparentid) {
		List<TblTargetTypeEntity> list = tblTargetTypeService.findByALLPatrnt(parentid);
		if (list != null && list.size() > 0) {
			for (TblTargetTypeEntity tblTargetType : list) {
				TblTargetTypeEntity target = new TblTargetTypeEntity();
				target.setCreateTime(tblTargetType.getCreateTime());
				target.setNbsjTemplete(temp);
				target.setParentId(new BigDecimal(newparentid));
				target.setStatus(TblTargetTypeEntity.ZY_NUMBER);
				target.setTargetDesc(tblTargetType.getTargetDesc());
				target.setTargetName(tblTargetType.getTargetName());
				tblTargetTypeService.save(target);
				List<TblAduitProGramEntity> grams = tblAduitProGramService.findByALL(tblTargetType.getTargetId().toString());
				if (grams != null && grams.size() > 0) {
					for (TblAduitProGramEntity gram : grams) {
						TblAduitProGramEntity prog = new TblAduitProGramEntity();
						prog.setBioData(gram.getBioData());
						prog.setTarget(target);
						prog.setBusinessType(gram.getBusinessType());
						prog.setStatus(TblAduitProGramEntity.ZY_NUMBER);
						prog.setCreateTime(gram.getCreateTime());
						prog.setControl(gram.getControl());
						//prog.setIsUseProgram(0);
						prog.setNbsjTemplete(temp);
						prog.setRiskPoint(gram.getRiskPoint());
						prog.setRiskSource(gram.getRiskSource());
						prog.setSuditProcess(gram.getSuditProcess());
						prog.setUpdateTime(gram.getUpdateTime());
						tblAduitProGramService.save(prog);
					}
				}
				capyMb(tblTargetType.getTargetId().toString(), temp, target.getTargetId().toString());
			}
		}
	}
    public void capyZY(String parentid, TblNbsjTempleteEntity temp, String newparentid) {
        List<TblTargetTypeEntity> list = tblTargetTypeService.findByALLPatrnt(parentid);
        if (list != null && list.size() > 0) {
            for (TblTargetTypeEntity tblTargetType : list) {
                TblTargetTypeEntity target = new TblTargetTypeEntity();
                target.setCreateTime(tblTargetType.getCreateTime());
                target.setNbsjTemplete(temp);
                target.setParentId(new BigDecimal(newparentid));
                target.setStatus(TblTargetTypeEntity.ZY_NUMBER);
                target.setTargetDesc(tblTargetType.getTargetDesc());
                target.setTargetName(tblTargetType.getTargetName());
                tblTargetTypeService.save(target);
                List<TblAduitProGramEntity> grams = tblAduitProGramService.findByALL(tblTargetType.getTargetId().toString());
                if (grams != null && grams.size() > 0) {
                    for (TblAduitProGramEntity gram : grams) {
                        TblAduitProGramEntity prog = new TblAduitProGramEntity();
                        prog.setBioData(gram.getBioData());
                        prog.setTarget(target);
                        prog.setBusinessType(gram.getBusinessType());
                        prog.setStatus(TblAduitProGramEntity.ZY_NUMBER);
                        prog.setCreateTime(gram.getCreateTime());
                        prog.setNbsjTemplete(temp);
                        prog.setRiskPoint(gram.getRiskPoint());
                        prog.setRiskSource(gram.getRiskSource());
                        prog.setSuditProcess(gram.getSuditProcess());
                        prog.setUpdateTime(gram.getUpdateTime());
                        tblAduitProGramService.save(prog);
                    }
                }
                capyZY(tblTargetType.getTargetId().toString(), temp, target.getTargetId().toString());
            }
        }
    }
    /**
     * 项目列表-添加审计模板
     *
     * @param request
     * @return
     
    @RequestMapping(value = "/xmgl/template_list/{list}")
    public ModelAndView xmgltemplate_list(@PathVariable String list, HttpServletRequest request,@RequestParam(value="idtype",required=false)String idtype,
    		@RequestParam(value="id",required=false)String id,@RequestParam(value = "templeteType", required = false) String templeteType) {
//        logger.info("项目管理-项目列表-添加审计模板");
        ModelAndView mv = new ModelAndView();
        
        if("yh".equals(idtype)){
        	id = userService.selectDeptIdForUserId(id);
        }
        int pageNumber = 1;
        String number = request.getParameter("pageNumber");
        if (number != null && number.length() > 0) {
            pageNumber = Integer.parseInt(number);
        }
        int type = TblNbsjTempleteEntity.ZY_TYPE;
        String url = "nbsj/xmgl/template_list_zy";
        if (list.equals("mb")) {
            type = TblNbsjTempleteEntity.MB_TYPE;
            url = "nbsj/xmgl/template_list";
        }
        //pageBean = this.tblNbsjTempleteService.findTemplete("", "", 1, type, pageNumber, pageBean.getPageSize());
        //pageBean = this.tblNbsjTempleteService.findTemplete("", "", 1, type, pageNumber, pageBean.getPageSize(),id);
		pageBean = this.tblNbsjTempleteService.findTempleteByType(templeteType, type, pageNumber,pageBean.getPageSize(), id);
        mv.setViewName(url);
        mv.addObject("pageBean", pageBean);
        mv.addObject("idtype", idtype);
        mv.addObject("templeteType", templeteType);
        mv.addObject("id", id);
        return mv;
    }
    /**
     * 项目列表-跳转添加小组
     *
     * @return
     
    @RequestMapping(value = "/xmgl/xmproject_plan_team_add")
    public ModelAndView xmproject_plan_team_add(HttpServletRequest request) {
//        logger.info("新建项目--添加小组");
        String pid = request.getParameter("projectid");
        ModelAndView mv = new ModelAndView();
        mv.addObject("pid", pid);
        String v = request.getParameter("v");
        mv.addObject("v",v);
        String cyId = request.getParameter("cyId");
        mv.addObject("cyId",cyId);
        String tId = request.getParameter("tId");
        mv.addObject("tId",tId);
      //查询框代码
        String choiceSearch = request.getParameter("choiceSearch");
        if(choiceSearch == null || "".equals(choiceSearch)) {
        	choiceSearch = "hide";
        }
        mv.addObject("choiceSearch",choiceSearch); 
        mv.setViewName("nbsj/xmgl/t06_project_team_add");
        return mv;
    }
    /**
     * 项目角色-跳转添加小组
     *
     * @return
     
    @RequestMapping(value = "/xmgl/auti_plan_team_add")
    public ModelAndView auti_plan_team_add(HttpServletRequest request) {
//        logger.info("新建项目--添加小组");
        String pid = request.getParameter("projectid");
        ModelAndView mv = new ModelAndView();
        mv.addObject("pid", pid);
        mv.setViewName("nbsj/xmgl/t06_project_auti_add");
        return mv;
    }
    /**
     * 项目角色-修改小组
     
    @RequestMapping(value = "/xmgl/auti_plan_team_modife")
    public ModelAndView auti_plan_team_modife(HttpServletRequest request) {
//        logger.info("新建项目--修改小组");
        String pid = request.getParameter("projectid");
        ModelAndView mv = new ModelAndView();
        String teamid = request.getParameter("teamid");
        if (teamid != null && teamid.length() > 0) {
            TblNbsjProjectTeamEntity team = tblnbsjProjectTeamService.getById(teamid);
            List<TblNbsjTeamstaffEntity> teamStaffs = team.getTeamStaffs();
            List<TblNbsjTeamstaffEntity> copyStaffs = new ArrayList<TblNbsjTeamstaffEntity>();
            copyStaffs.addAll(teamStaffs);
            Iterator<TblNbsjTeamstaffEntity> it = copyStaffs.iterator();
            while (it.hasNext()) {
                TblNbsjTeamstaffEntity staff = it.next();
                if (staff.getStafftype().equals(TblNbsjTeamstaffEntity.LEADER)) {
                    mv.addObject("leader", staff.getStaff());
                    it.remove();
                }
            }
            mv.addObject("list", copyStaffs);
            mv.addObject("team", team);
        }
        mv.addObject("pid", pid);
        mv.setViewName("nbsj/xmgl/t06_project_auti_add");
        return mv;
    }
    /**
     * 保存指派人员
     *
     * @param request
     * @return
     
    @RequestMapping(value = "/xmgl/update_plan_user_save")
    public
    @ResponseBody
    String zhip_plan_team_save(HttpServletRequest request) {
        String str = "1";
        String pmid = request.getParameter("pmid");
        String projectid = request.getParameter("pid");
        String umpireid = request.getParameter("umpireid");
        String controlid = request.getParameter("controlid");
        String strs = request.getParameter("str");
        if (projectid != null && projectid.length() > 0) {
            TblNbsjProjectEntity project = tblnbsjProjectService.getById(projectid);
            if (strs != null && strs.equals("1")) {
                TblStaff pm = null;// tblStaffService.findById(pmid);
                project.setAssigbedpmTime(new Date());
                project.setTblPm(pm);
            }
            if (strs != null && strs.equals("2")) {
                TblStaff ump = null;// tblStaffService.findById(umpireid);
                project.setAssigbedumpeTime(new Date());
                project.setTblumpe(ump);
            }
            if (strs != null && strs.equals("3")) {
                TblStaff con = null;// tblStaffService.findById(controlid);
                project.setAssigbedControlTime(new Date());
                project.setTblcontrol(con);
            }
            try {
                tblnbsjProjectService.saveOrUpdate(project);
            } catch (Exception e) {
                str = "2";
                e.printStackTrace();
            }
        }
        return str;
    }
    /**
     * 项目角色-保存小组
     *
     * @return
     
    @RequestMapping(value = "/xmgl/auti_plan_team_save")
    public
    @ResponseBody
    String auti_plan_team_save(HttpServletRequest request) {
        TblStaff creator = (TblStaff) request.getSession().getAttribute("longUser");
        try {
            String userid = request.getParameter("userid");
            String staffid = request.getParameter("staffid");
            String teamName = request.getParameter("teamName");
            String teamid = request.getParameter("teamid");
            String pid = request.getParameter("pid");
            TblNbsjProjectTeamEntity team = null;
            if (teamid != null && teamid.length() > 0) {
                TblNbsjProjectTeamEntity projectTeam = tblnbsjProjectTeamService.getById(teamid);
//                logger.info("项目角色--修改项目--小组成员");
                Date createTime = projectTeam.getCreateTime();
                tblnbsjProjectTeamService.deleteProjectTeamInfo(Integer.valueOf(pid),Integer.valueOf(teamid));
                team = new TblNbsjProjectTeamEntity();
                team.setTeamName(teamName);
                team.setCreateTime(createTime);
                team.setCreateUserId(creator.getStaffid().intValue());
            } else {
//                logger.info("新建项目--小组成员");
                team = new TblNbsjProjectTeamEntity();
                team.setCreateUserId(creator.getStaffid().intValue());
                team.setCreateTime(new Date());
                team.setTeamName(teamName);
            }
            if (pid != null && pid.length() > 0) {
                TblNbsjProjectEntity project = tblnbsjProjectService.getById(pid);
                team.getTblTeamProjects().add(project);
            }
            if (staffid != null && staffid.length() > 0) {
                TblStaff staff = null;// tblStaffService.findById(staffid);
                if (userid != null && userid.length() > 0) {
                    String[] strs = userid.split(",");
                    List<TblStaff> crewList = new ArrayList<TblStaff>();
                    for (String string : strs) {
                        if (StringUtils.isNotBlank(string)) {
                            TblStaff crew = null;// tblStaffService.findById(string.trim());
                            crewList.add(crew);
                        }
                    }
                    tblnbsjProjectTeamService.saveTblNbsjProjectteam(team);
                    return JsonBean.success();
                }
            }
        } catch (Exception e) {
            return JsonBean.error();
        }
        return JsonBean.error();
    }
    /**
     * 项目角色-指派人员
     *
     * @return
     
    @RequestMapping(value = "/xmgl/role_manage_assign")
    public ModelAndView role_manage_assign(HttpServletRequest request) {
        String projectid = request.getParameter("projectid");
        String str = request.getParameter("str");
        ModelAndView mv = new ModelAndView();
        if (projectid != null && projectid.length() > 0) {
            TblNbsjProjectEntity project = tblnbsjProjectService.getById(projectid);
            mv.addObject("pro", project);
        }
        mv.addObject("str", str);
        mv.setViewName("nbsj/xmgl/role_manage_assign");
        return mv;
    }
    /**
     * 项目列表-修改小组
     *
     * @return
     
    @RequestMapping(value = "/xmgl/xmproject_plan_team_modife")
    public ModelAndView xmproject_plan_team_modife(HttpServletRequest request) {
//        logger.info("新建项目--修改小组");
        String pid = request.getParameter("projectid");
        ModelAndView mv = new ModelAndView();
        String teamid = request.getParameter("teamid");
        if (teamid != null && teamid.length() > 0) {
            TblNbsjProjectTeamEntity team = tblnbsjProjectTeamService.getById(teamid);
            List<TblNbsjTeamstaffEntity> teamStaffs = team.getTeamStaffs();
            List<TblNbsjTeamstaffEntity> copyStaffs = new ArrayList<TblNbsjTeamstaffEntity>();
            copyStaffs.addAll(teamStaffs);
            Iterator<TblNbsjTeamstaffEntity> it = copyStaffs.iterator();
            while (it.hasNext()) {
                TblNbsjTeamstaffEntity staff = it.next();
                if (staff.getStafftype().equals(TblNbsjTeamstaffEntity.LEADER)) {
                    mv.addObject("leader", staff.getStaff());
                    it.remove();
                }
            }
            mv.addObject("list", copyStaffs);
            mv.addObject("team", team);
        }
        mv.addObject("pid", pid);
        String v = request.getParameter("v");
        mv.addObject("v",v);
        String cyId = request.getParameter("cyId");
        mv.addObject("cyId",cyId);
        String tId = request.getParameter("tId");
        mv.addObject("tId",tId);
      //查询框代码
        String choiceSearch = request.getParameter("choiceSearch");
        if(choiceSearch == null || "".equals(choiceSearch)) {
        	choiceSearch = "hide";
        }
        mv.addObject("choiceSearch",choiceSearch);
        mv.setViewName("nbsj/xmgl/t06_project_team_add");
        return mv;
    }
    /**
     * 项目列表-保存小组
     *
     * @return
     
    @RequestMapping(value = "/xmgl/xmproject_plan_team_save")
    public
    @ResponseBody
    String xmproject_plan_team_save(HttpServletRequest request) {
        TblStaff creator = (TblStaff) request.getSession().getAttribute("longUser");
        try {
            String userid = request.getParameter("userid");
            String staffid = request.getParameter("staffid");
            String teamName = request.getParameter("teamName");
            String teamid = request.getParameter("teamid");
            String pid = request.getParameter("pid");
            TblNbsjProjectTeamEntity team = null;
            if (teamid != null && teamid.length() > 0) {
                TblNbsjProjectTeamEntity projectTeam = tblnbsjProjectTeamService.getById(teamid);
//                logger.info("项目角色--修改项目--小组成员");
                Date createTime = projectTeam.getCreateTime();
                tblnbsjProjectTeamService.deleteProjectTeamInfo(Integer.valueOf(pid),Integer.valueOf(teamid));
                team = new TblNbsjProjectTeamEntity();
                team.setTeamName(teamName);
                team.setCreateTime(createTime);
                team.setCreateUserId(creator.getStaffid().intValue());
            } else {
//                logger.info("新建项目--小组成员");
                team = new TblNbsjProjectTeamEntity();
                team.setCreateUserId(creator.getStaffid().intValue());
                team.setCreateTime(new Date());
                team.setTeamName(teamName);
            }
            if (pid != null && pid.length() > 0) {
                TblNbsjProjectEntity project = tblnbsjProjectService.getById(pid);
                team.getTblTeamProjects().add(project);
            }
            if (staffid != null && staffid.length() > 0) {
                TblStaff staff = null;// tblStaffService.findById(staffid);
                if (userid != null && userid.length() > 0) {
                    String[] strs = userid.split(",");
                    List<TblStaff> crewList = new ArrayList<TblStaff>();
                    for (String string : strs) {
                        if (StringUtils.isNotBlank(string)) {
                            TblStaff crew = null;// tblStaffService.findById(string.trim());
                            crewList.add(crew);
                        }
                    }
                    tblnbsjProjectTeamService.save(team);
                    return JsonBean.success();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return JsonBean.error();
        }
        return JsonBean.error();
    }
//    /**
//     * 项目列表-添加项目对象
//     *
//     * @param request
//     * @return
//     
//    @RequestMapping(value = "/xmgl/xmproject_plan_audit_save")
//    public
//    @ResponseBody
//    String xmproject_plan_audit_save(HttpServletRequest request) {
//        String pid = request.getParameter("pid");
//        String key = request.getParameter("key");
////        logger.info("项目--添加项目对象");
//        if (pid != null && pid.length() > 0 && key != null && key.length() > 0) {
//            TblNbsjProjectEntity project = tblnbsjProjectService.getById(pid);
//            String[] strs = key.split(",");
//            for (String string : strs) {
//                TblOrganization organization = organizationService.findById(string);
//                organization.getTblOrgeProjects().add(project);
//                organizationService.modify(organization);
//            }
//        }
//        return "";
//    }
//    /**
//     * 项目列表-删除项目对象
//     *
//     * @param request
//     * @return
//     
//    @RequestMapping(value = "/xmgl/delete_projecct_audit")
//    public
//    @ResponseBody
//    String delete_projecct_audit(HttpServletRequest request) {
//        String auditid = request.getParameter("auditid");
//        String projectid = request.getParameter("projectid");
////        logger.info("项目--删除项目对象");
//        if (auditid != null && auditid.length() > 0 && projectid != null && projectid.length() > 0) {
//            TblNbsjProjectEntity project = tblnbsjProjectService.getById(projectid);
//            TblOrganization organization = organizationService.findById(auditid);
//            organization.getTblOrgeProjects().remove(project);
//            organizationService.modify(organization);
//        }
//        return "";
//    }
    /**
     * 项目列表-删除项目
     
    @RequestMapping(value = "/xmgl/xmproject_plan_delete", produces = "application/json; charset=utf-8")
    public
    @ResponseBody
    String xmproject_plan_delete(HttpServletRequest request) {
        String projectid = request.getParameter("projectid");
//        logger.info("项目--删除项目");
        if (projectid != null && projectid.length() > 0) {
            TblNbsjProjectEntity project = tblnbsjProjectService.getById(projectid);
            if (project.getStatus() == 0) {
                Set<TblNbsjProjectTeamEntity> teams = project.getTblProjectTeams();
                if (teams != null && teams.size() > 0) {
                    for (TblNbsjProjectTeamEntity team : teams) {
                        tblnbsjProjectTeamService.deleteProjectTeamInfo(Integer.valueOf(projectid), team.getTeamId());
                    }
                }
                if(project.getTemp()!=null){
                	String templete = project.getTemp().getTempleteId().toString();
                	try {
                		if(templete!=null){
                			tblAduitProGramService.deleteZy(templete);
                			tblTargetTypeService.deleteByZY(templete);
                			tblNbsjTempleteService.delete(new BigDecimal(project.getTemp().getTempleteId()));
                		}
                		
                	} catch (Exception e) {
                		if(project!=null && project.getTblprojectAtts() !=null && project.getTblprojectAtts().size()>0){
                			return JsonBean.error("请先删除项目附件");
                    }else {
                    	return JsonBean.error("删除失败");
                    }

                }
                
                }
            	tblnbsjProjectService.delete(project);
            	return JsonBean.success("删除成功！");
            } else {
                return JsonBean.error("该项目已启动不能删除");
            }
        } else {
            return JsonBean.error("请选择删除的项目");
        }
    }
    /**
     * 项目列表-判断项目是否启动
     *
     * @param request
     * @return
     
    @RequestMapping(value = "/xmgl/xmproject_plan_is", produces = "application/json; charset=utf-8")
    public
    @ResponseBody
    String xmproject_plan_is(HttpServletRequest request) {
        String projectid = request.getParameter("projectid");
//        logger.info("判断项目是否启动");
        if (projectid != null && projectid.length() > 0) {
            TblNbsjProjectEntity project = tblnbsjProjectService.getById(projectid);
            if (project.getStatus() == 0) {
                return JsonBean.success();
            } else {
                return JsonBean.error("该项目已启动不能修改");
            }
        } else {
            return JsonBean.error("请选择修改的项目");
        }
    }
    /**
     * 项目列表-项目实施
     *
     * @param request
     * @return
     
    @RequestMapping(value = "/xmgl/xmproject_plan_cycurr", produces = "application/json; charset=utf-8")
    public
    @ResponseBody
    String xmproject_plan_cycurr(HttpServletRequest request) {
        String projectid = request.getParameter("projectid");
        TblStaff tblStaff = (TblStaff) request.getSession().getAttribute("longUser");
//        logger.info("选择项目进行实施");
        if (StringUtils.isNotBlank(projectid)) {
            TblNbsjProjectEntity project = tblnbsjProjectService.getById(projectid);
            if (null != project && project.getUpdateStatus().equals(TblNbsjProjectEntity.UPDATEYES)) {
                if (project.getStatus() != null && project.getStatus() == 0) {
                    return JsonBean.error("该项目未启动，不能实施");
                } else if (null != project.getStatus() && project.getStatus().equals(3) && project.getStatus().equals(4)) {
                    return JsonBean.error("项目已完成，不能再次实施");
                } else {
                    if (null == project.getImplementTime()) {
                        project.setImplementTime(new Date());
                    }
                    //TblNbsjStaffSelect oldtblNbsjStaffSelect = this.tblNbsjStaffSelectService.findByUserId(tblStaff.getStaffid());
                    //修改实施过的项目
                    //if(null!=oldtblNbsjStaffSelect) {
                   // 	TblnbsjProject oldProject = tblnbsjProjectService.getId(oldtblNbsjStaffSelect.getProjectId().toString());
                   // 	oldProject.setCyrrentStatre(TblnbsjProject.NO_SELECT);
                  //  	oldProject.setStatus(1);//修改已实施过的项目为启动
                   // }
                    //实施的项目
                   // project.setCyrrentStatre(TblnbsjProject.YE_SELECT);
                   // project.setStatus(1);//status=2  实施中
                    //TODO  实施项目是否与个人绑定?
                    this.tblNbsjStaffSelectService.deleteByuserId(tblStaff.getStaffid());
                    TblNbsjStaffSelectEntity nbsjStaffSelect = new TblNbsjStaffSelectEntity();
                    nbsjStaffSelect.setProjectId(new BigDecimal(projectid));
                    nbsjStaffSelect.setStaffId(tblStaff.getStaffid());
                    this.tblNbsjStaffSelectService.save(nbsjStaffSelect);
                    tblnbsjProjectService.saveOrUpdate(project);
                    return JsonBean.success();
                }
            } else {
                return JsonBean.error("项目不完整，请完善项目！");
            }
        } else {
            return JsonBean.error("请选择项目");
        }
    }
    /**
     * 项目角色-启动项目
     *
     * @param request
     * @return
     
    @RequestMapping(value = "/xmgl/xmproject_plan_upstatus", produces = "application/json; charset=utf-8")
    public
    @ResponseBody
    String xmproject_plan_upstatus(HttpServletRequest request) {
        String projectid = request.getParameter("projectid");
//        logger.info("启动项目");
        if (projectid != null && projectid.length() > 0) {
            TblNbsjProjectEntity project = tblnbsjProjectService.getById(projectid);
            project.setStatus(1);//项目状态
            project.setFpStatus(3);//任务状态：启动
            tblnbsjProjectService.saveOrUpdate(project);
            return JsonBean.success("启动成功");
        } else {
            return JsonBean.error("请选择启动的项目");
        }
    }
    @RequestMapping(value = "/xmgl/delete_projecct_team")
    public
    @ResponseBody
    String delete_projecct_team(HttpServletRequest request) {
        String teamid = request.getParameter("teamid");
//        logger.info("项目--删除小组成员");
        if (teamid != null && teamid.length() > 0) {
            TblNbsjProjectTeamEntity team = tblnbsjProjectTeamService.getById(teamid);
            tblnbsjProjectTeamService.deleteProjectTeamInfo(null, Integer.valueOf(teamid));
        }
        return "";
    }
    @RequestMapping(value = "/xmgl/delete_projecct_teamByid")
    public
    @ResponseBody
    String delete_projecct_teamByid(HttpServletRequest request) {
    	String teamid = request.getParameter("teamid");
//    	logger.info("项目--删除小组成员");
    	if (teamid != null && teamid.length() > 0) {
    		TblNbsjProjectTeamEntity team = tblnbsjProjectTeamService.getById(teamid);
    		tblnbsjProjectTeamService.deleteProjectTeamInfo(null, Integer.valueOf(teamid));
    	}
    	return JsonBean.success();
    }
    /**
     * 项目新建-选择项目经理
     *
     * @param request
     * @return
     
    @RequestMapping(value = "/user/indexs")
    public ModelAndView userIndex(HttpServletRequest request) {
        ModelAndView mv = new ModelAndView("/nbsj/xmgl/index");
        String num = request.getParameter("type");
        mv.addObject("type", num);
        return mv;
    }
    /**
     * 项目新建-选择项目经理-左侧tree
     *
     * @param request
     * @return
     
    @RequestMapping(value = "/user/lefts")
    public ModelAndView userLeft(HttpServletRequest request) {
        // OrganizationService service =
        // (OrganizationService)SpringContextHolder.getBean("OrgService");
        TblOrganization attribute1 = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");// 当前用户的机构
		/*
		 * TblStaff user = (TblStaff)
		 * request.getSession().getAttribute("longUser"); TblOrganization o =
		 * treeService
		 * .belongToCompany(user.getTblOrganization().getOrgid().toString());
		 * String tree = service.getOrgTree(attribute1.getOrgid());
		 
        ModelAndView mv = new ModelAndView("/nbsj/xmgl/user_left");
        // mv.addObject("tree", tree);
        String num = request.getParameter("type");
        mv.addObject("type", num);
        mv.addObject("orgid", attribute1.getOrgid());
        mv.addObject("targetFrame", "mainFramex");
        return mv;
    }
    
    /**
	 * 附件列表页面
	 *
	 * @param request
	 * @return
	 
	@RequestMapping(value = "/sjgl/dgfjlist_download")
	public ModelAndView dgfjlist_download(HttpServletRequest request,
			@RequestParam(value="pageNumber",required=false)Integer pageNumber,
			@RequestParam(value="attname",required=false)String attName) {
		ModelAndView mv = new ModelAndView();
		try {
			TblOrganization org = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");// 选则的机构
			PageInfo<TblAttachmentEntity> pageInfo = new PageInfo<TblAttachmentEntity>();
			if(pageNumber == null){
				pageNumber = 1;
			}
			pageInfo.setCurrentPage(pageNumber);
			TblAttachmentEntity tac = new TblAttachmentEntity();
			tac.setAttname(attName);
			pageInfo.setCondition(tac);
			attachmentService.findAllFjByAllProject(pageInfo,org.getOrgid());
			
			String choiceSearch = request.getParameter("choiceSearch");
			if(choiceSearch == null || "".equals(choiceSearch)) {
				choiceSearch = "hide";
			}
			mv.addObject("choiceSearch",choiceSearch); 					
			
			mv.addObject("pageInfo", pageInfo);
			mv.setViewName("/nbsj/sjgl/dgfjlist_download");
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		// 当前实施的项目
		TblNbsjProjectEntity selectProject = this.tblnbsjProjectService.getSelectProject();
		TblOrganization attribute1 = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");// 当前用户的机构
		// 可以查看管理的人员,稽核部负责人和项目负责人
		List<BigDecimal> list = null;// tblStaffService.findTaskControlPerson(selectProject.getProjectId(),	attribute1.getOrgid());
		// 当前登陆用户
		TblStaff user = (TblStaff) request.getSession().getAttribute("longUser");
/*			if (!list.contains(user.getStaffid())) {
			setErrorJsp("004");
			mv.setViewName("nbsj/main41");
		}
		//查询框代码
		String choiceSearch = request.getParameter("choiceSearch");
		if(choiceSearch == null || "".equals(choiceSearch)) {
			choiceSearch = "hide";
		}
		mv.addObject("choiceSearch",choiceSearch); 
		return mv;
	}
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    /**
     * @Author: TYB
     * @Date: 2017-04-10 下午 1:19
     * @Des: 后台报错跳转error页时传递提示
    *  data:001:未选择项目  002:项目未添加指引模板
    
   	public void setErrorJsp(String data,HttpServletRequest request){
   		request.getSession().removeAttribute("ErrorJsp");
   		request.getSession().setAttribute("ErrorJsp",data);
   	}*/
}
